<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui"
	xmlns:cc="http://java.sun.com/jsf/composite"
	xmlns:hmrSearch="http://java.sun.com/jsf/composite/search"
	xmlns:hmrDetail="http://java.sun.com/jsf/composite/detail"	>

<cc:interface>
	<cc:attribute name="handler"				type="com.hemerasolutions.v2trainer.component.interfaces.search.ExerciseSearchCompInterface" required="true"/>
	<cc:attribute name="oncomplete"				type="java.lang.String" default="" required="false"/>
	<cc:attribute name="update"					type="java.lang.String" default="" required="false"/>
	
</cc:interface>

<cc:implementation>
	<span id="#{cc.clientId}" >
		<h:form id="findExerciseForm" prependId="false">
			<h:panelGrid columns="4" cellpadding="2">
				<h:outputLabel 	value="#{msgs.Name}: " 	 />
				<p:inputText	value="#{ cc.attrs.handler.findExerciseByName}" 			maxlength="50" 	size="20" />
				<p:spacer/>
				<p:spacer/>

				<h:outputLabel 	value="#{msgs.Description}: " />
				<p:inputText	value="#{ cc.attrs.handler.findExerciseByDescription}"		maxlength="100" 	size="45" />
				<p:spacer/>
				<p:spacer/>
 
	            <h:outputLabel value="#{msgs.Technical}: " />
				<p:selectBooleanCheckbox  value="#{cc.attrs.handler.findExerciseByTechnical}"  />   
				<p:spacer/>
				<p:spacer/>
 
				<h:outputText value="#{msgs.Modality}: " style="white-space: nowrap;"/>
				<p:commandButton value="#{msgs.Select}" oncomplete="wfindModalityDialog_#{cc.id}.show();"/>
										
				<h:outputText value="#{msgs.BodyRegions}: "  />
	 			<p:selectCheckboxMenu id="bodyRegionSelect" value="#{cc.attrs.handler.findExerciseByBodyRegions}" converter="#{genericConverter}" 
					filter="true" panelStyle="width:220px" label="#{msgs.BodyRegions}" > 
		          	<f:selectItems value="#{cc.attrs.handler.fullBodyRegions}" var="bodyRegion" itemLabel="#{msgs[bodyRegion.name]}" itemValue="#{bodyRegion}" />
					<p:ajax  listener="#{cc.attrs.handler.changeFullBodyRegions}" update="muscleGroupSelect"/>
		        </p:selectCheckboxMenu>

				<h:outputText value="#{cc.attrs.handler.exerciseGroup.trainingType.name}" style="white-space: nowrap;" rendered="#{cc.attrs.exerciseGroup.modality != null}"/>
				<h:outputText value="#{cc.attrs.handler.exerciseGroup.modality.name} - #{msgs.Version}: #{cc.attrs.handler.exerciseGroup.modality.version} " 
					rendered="#{cc.attrs.exerciseGroup.modality != null}"	style="white-space: nowrap;"/>


				<h:outputText value="#{msgs.MuscleGroups}: "  />
	 			<p:selectCheckboxMenu id="muscleGroupSelect" value="#{cc.attrs.handler.findExerciseByMuscleGroups}" converter="#{genericConverter}" 
					filter="true" panelStyle="width:220px" label="#{msgs.MuscleGroups}" disabled="#{empty cc.attrs.handler.fullMuscleGroups}" >
					<f:selectItems value="#{cc.attrs.handler.fullMuscleGroups}" var="muscleGroup" itemLabel="#{msgs[muscleGroup.name]}" itemValue="#{muscleGroup}" />
					<p:ajax listener="#{cc.attrs.handler.changeFullMuscleGroups}" update="muscleSelect"/>
		        </p:selectCheckboxMenu>
		        
				<h:outputText  value="#{msgs.Executions}" />
				<p:selectCheckboxMenu id="executionTypeSelect" value="#{cc.attrs.handler.findExerciseByExecutions}" converter="#{genericConverter}" 
					filter="true" panelStyle="width:220px" label="#{msgs.Executions}" disabled="#{empty cc.attrs.handler.fullExecutions}" >
	            	<f:selectItems value="#{cc.attrs.handler.fullExecutions}"  var="execution" itemLabel="#{msgs[execution.name]}" itemValue="#{execution}" />
				</p:selectCheckboxMenu>

				<h:outputText value="#{msgs.Muscles}: " />
	 			<p:selectCheckboxMenu id="muscleSelect" value="#{cc.attrs.handler.findExerciseByMuscles}" converter="#{genericConverter}" 
					filter="true" panelStyle="width:220px" label="#{msgs.Muscles}" disabled="#{empty cc.attrs.handler.fullMuscles}" > 
		          	<f:selectItems value="#{cc.attrs.handler.fullMuscles}" var="muscle" itemLabel="#{msgs[muscle.name]}" itemValue="#{muscle}" />
		        </p:selectCheckboxMenu>

			</h:panelGrid>		
 
			<p:commandButton value="#{ msgs.Search}"	actionListener="#{cc.attrs.handler.searchExercises}" update=":growl, panelFoundExercisesTable" 	icon=" ui-icon-search"  process="@form" />
			<p:commandButton value="#{ msgs.Clear}"		type="button"	icon="ui-icon-clean">
				 <p:ajax update="findExerciseForm" resetValues="true" />  	
			</p:commandButton>
			
			
			<p:outputPanel id="panelFoundExercisesTable" layout="block" >
				<p:spacer height="20" rendered="#{not empty cc.attrs.handler.foundExercises}"  />

				<p:dataTable id="foundExercisesTable" value="#{cc.attrs.handler.foundExercises}" var="exercise" paginator="true"  rendered="#{not empty cc.attrs.handler.foundExercises}" 
					paginatorAlwaysVisible="false"  paginatorPosition="bottom" rows="4" emptyMessage="#{msgs.NoResults}" >   
					<p:columnGroup type="header" >  
						<p:row>
							<p:column colspan="6" style="text-align:center;">
								<f:facet name="header">
									<h:outputText value="#{msgs.Exercises}" />
								</f:facet>
							</p:column>
		
						</p:row>
						<p:row>
							<p:column	colspan="3" >
								<f:facet name="header">
									<h:outputText value="#{msgs.Name}"/>
								</f:facet>
							</p:column>
							<p:column	colspan="1" style="padding:0px;margin:0px;">
								<f:facet name="header">
									<h:outputText value="#{msgs.Description}"/>
								</f:facet>
							</p:column>
							<p:column	colspan="2" style="padding:0px;margin:0px;">
								<f:facet name="header">
									<h:outputText value="#{msgs.CreatedAt}"/>
								</f:facet>
							</p:column>		
						</p:row>	 
					</p:columnGroup>
					<p:column colspan="1" headerText="#{msgs.Name}" >
						<h:outputText value="#{exercise.name}" />
					</p:column>
		
					<p:column colspan="1" styleClass="ui-table-button-row" >
						<p:commandButton	action="#{cc.attrs.handler.toViewExercise}"  title="#{msgs.View}" icon="ui-icon-search" update=":#{cc.clientId}:exerciseDialog" 
							oncomplete="wexerciseDialog_#{cc.id}.show()"  styleClass="ui-table-button" process="@this">
							<f:setPropertyActionListener target="#{cc.attrs.handler.exercise}" value="#{exercise}"/>
						</p:commandButton>
					</p:column>
					<p:column colspan="1" styleClass="ui-table-button-row"  >
						<p:commandButton title="#{msgs.Add}"  action="#{cc.attrs.handler.addExerciseStep}" update="@form:panelFoundExercisesTable, #{cc.attrs.update}" 
							icon="ui-icon-plus" styleClass="ui-table-button" oncomplete="#{cc.attrs.oncomplete}" process="@this" >
							<f:setPropertyActionListener target="#{cc.attrs.handler.selExercise}" value="#{exercise}"/>
						</p:commandButton>
					</p:column>		
					<p:column headerText="#{msgs.Description}" >
						<h:outputText value="#{exercise.description}" />
					</p:column>		
					<p:column colspan="2" headerText="#{msgs.CreatedAt}">
						<h:outputText value="#{exercise.createdAt}">
							<f:convertDateTime locale="pt" dateStyle="long" pattern="dd/MM/yyyy HH:mm" />
						</h:outputText>
					</p:column>		
				</p:dataTable>	
			</p:outputPanel>	
		</h:form>			
	</span>

	<p:dialog id="exerciseDialog" header="#{msgs.Exercise}" modal="true" appendTo="@(body)" widgetVar="wexerciseDialog_#{cc.id}" style="width:90%"> 
		<hmrDetail:exerciseDetails handler="#{cc.attrs.handler.exerciseDetailsHandler}" 
			editable="false"
			intensitySummary="true" />

		<div align="left"   > 
			<p:commandButton type="button" value="#{msgs.Cancel}"		icon="ui-icon-cancel" onclick="wexerciseDialog_#{cc.id}.hide()"/>
		</div>
	</p:dialog>


	<p:dialog id="exerciseDialog" header="#{msgs.Exercise}" modal="true" appendTo="@(body)" widgetVar="wexerciseDialog_#{cc.id}" style="width:90%"> 
		<hmrDetail:exerciseDetails handler="#{cc.attrs.handler.exerciseDetailsHandler}" 
			editable="false"
			intensitySummary="true" />

		<div align="left"   > 
			<p:commandButton type="button" value="#{msgs.Cancel}"		icon="ui-icon-cancel" onclick="wexerciseDialog_#{cc.id}.hide()"/>
		</div>
	</p:dialog>

	<p:dialog id="modalitySearchDialog" header="#{msgs.FindModality}" modal="true" appendTo="@(body)"  widgetVar="wfindModalityDialog_#{cc.id}">
		<hmrSearch:modalitySearch handler="#{cc.attrs.handler.modalitySearch}" showResultsPanel="true" 
			updateOnSelect=":#{cc.clientId}:exerciseDialog" onCompleteSelect="wfindModalityDialog_#{cc.id}.hide();"   />
	</p:dialog>		

</cc:implementation>
</html>	